package br.gov.mi.corporativo.configuracao;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.LocalEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.jta.JtaTransactionManager;

@Configuration
@ComponentScan("br.gov.mi.corporativo")
@ImportResource({ "classpath:/META-INF/ws-context.xml" })
@EnableJpaRepositories(basePackages = { "br.gov.mi.corporativo.dominio.repositorio" })
public class CorporativoConfig {

	// Configuracao para uso do gerenciador de transacoes do jboss (JTA)
	@Bean
	public PlatformTransactionManager transactionManager() {
		JtaTransactionManager txManager = new JtaTransactionManager();

		return txManager;
	}

	// Definicao da entity manager fatory
	@Bean
	public LocalEntityManagerFactoryBean entityManagerFactory() {
		LocalEntityManagerFactoryBean em = new LocalEntityManagerFactoryBean();
		em.setPersistenceUnitName("CORPORATIVO");
		return em;
	}
}
